<form id="config-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">产品区域:</label>
        <div class="col-xs-6 col-sm-4">
            <select name="row[product_father]" class="form-control s_sel" f="product">
                {foreach $product_data as $item}
                <option value="{$item['id']}" {if $item['id'] == $defult_index['product_father']}selected{/if}>{$item['name']}/{$item['e_name']}</option>
                {/foreach}
            </select>
        </div>
        <div class="col-xs-6 col-sm-4">
            <select name="row[product_son]" class="form-control" id="product">
                {foreach $product_data as $item}
                    {if $item['id'] == $defult_index['product_father']}
                        {foreach $item['son'] as $val}
                            <option value ="{$val['id']}" {if $val['id'] == $defult_index['product_son']}selected{/if}>{$val['name']}/{$val['e_name']}</option>
                        {/foreach}
                    {/if}
                {/foreach}
            </select>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">内容区:</label>
        <div class="col-xs-12 col-sm-8">
            <select name="row[serve]" class="form-control">
                {foreach $all_category as $item}
                    <option value="{$item['id']}" {if $item['id'] == $defult_index['serve']}selected{/if} {if $item['official_rule_id'] != 3}disabled="disabled"{/if}>{$item['name']}/{$item['e_name']}</option>
                {/foreach}
            </select>
        </div>
    </div>


    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">新闻部分:</label>
        <div class="col-xs-6 col-sm-4">
            <select name="row[journalism_father]" class="form-control s_sel" f="journalism">
                {foreach $journalism_data as $item}
                <option value ="{$item['id']}" {if $item['id'] == $defult_index['journalism_father']}selected{/if}>{$item['name']}/{$item['e_name']}</option>
                {/foreach}
            </select>
        </div>
        <div class="col-xs-6 col-sm-4">
            <select name="row[journalism_son]" class="form-control" id="journalism">
                {foreach $journalism_data as $item}
                    {if $item['id'] == $defult_index['journalism_father']}
                        {foreach $item['son'] as $val}
                            <option value ="{$val['id']}" {if $val['id'] == $defult_index['journalism_son']}selected{/if}>{$val['name']}/{$val['e_name']}</option>
                        {/foreach}
                    {/if}
                {/foreach}
            </select>
        </div>
    </div>


    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">底部区域:</label>
        <div class="col-xs-12 col-sm-8">
            <select name="row[our_clients]" class="form-control">
                {foreach $all_category as $item}
                <option value="{$item['id']}" {if $item['id'] == $defult_index['our_clients']}selected{/if} {if $item['official_rule_id'] != 9}disabled="disabled"{/if}>{$item['name']}/{$item['e_name']}</option>
                {/foreach}
            </select>
        </div>
    </div>



    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>

<script src="/assets/libs/jquery/dist/jquery.min.js"></script>
<script>
    $('.s_sel').change(function() {
        //产品数据
        var product_data = '{:json_encode($product_data)}';
        var product_father = "{$defult_index['product_son']}";
        //新闻数据
        var journalism_data = '{:json_encode($journalism_data)}';
        var journalism_father = "{$defult_index['journalism_son']}";
        //获取自定义属性
        var f = $(this).attr('f');
        //获取当前的val
        var val = $(this).val();
        //请求数据
        var item
        var data;
        var def;
        if(f == 'product'){
            data = product_data;
            def = product_father;
        };
        if(f == 'journalism'){
            data = journalism_data
            def = journalism_father;
        };
        //循环数据
        data = JSON.parse(data);
        Object.keys(data).forEach(index => {
            item = data[index];
            if(item['id'] == val){
                var str = "";
                $('#'+ f).html('');
                item.son.forEach((item)=>{
                    var selected = '';
                    if(def == item['id']){
                        selected = 'selected';
                    }
                    str += "<option value='"+item['id']+"' "+selected+">"+item['name']+"/"+item['e_name']+"</option>"
                })
                $('#'+ f).html(str);
            }
            return true  //返回true    foreach的return 不会跳出循环
        })

        // console.log(data)
        //
        // console.log(f)
        //
        // //一:
        // console.log($(this).val());
        // //二:
        // var options=$("#select option:selected");
        // console.log(options.val());
    });
</script>